package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Manholes;
import com.ruoyi.system.service.IManholesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 炮筒表Controller
 * 
 * @author ruoyi
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/system/manholes")
public class ManholesController extends BaseController
{
    @Autowired
    private IManholesService manholesService;

    /**
     * 查询炮筒表列表
     */
    @PreAuthorize("@ss.hasPermi('system:manholes:list')")
    @GetMapping("/list")
    public TableDataInfo list(Manholes manholes)
    {
        startPage();
        List<Manholes> list = manholesService.selectManholesList(manholes);
        return getDataTable(list);
    }

    /**
     * 导出炮筒表列表
     */
    @PreAuthorize("@ss.hasPermi('system:manholes:export')")
    @Log(title = "炮筒表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Manholes manholes)
    {
        List<Manholes> list = manholesService.selectManholesList(manholes);
        ExcelUtil<Manholes> util = new ExcelUtil<Manholes>(Manholes.class);
        util.exportExcel(response, list, "炮筒表数据");
    }

    /**
     * 获取炮筒表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:manholes:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(manholesService.selectManholesById(id));
    }

    /**
     * 新增炮筒表
     */
    @PreAuthorize("@ss.hasPermi('system:manholes:add')")
    @Log(title = "炮筒表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Manholes manholes) {
        int result = manholesService.insertManholes(manholes);
        if (result > 0) {
            // 返回插入后的Manholes对象
            return AjaxResult.success(manholes);
        } else {
            return AjaxResult.error("新增失败");
        }
    }

    /**
     * 修改炮筒表
     */
    @PreAuthorize("@ss.hasPermi('system:manholes:edit')")
    @Log(title = "炮筒表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Manholes manholes)
    {
        return toAjax(manholesService.updateManholes(manholes));
    }

    /**
     * 删除炮筒表
     */
    @PreAuthorize("@ss.hasPermi('system:manholes:remove')")
    @Log(title = "炮筒表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(manholesService.deleteManholesByIds(ids));
    }
}
